package com.t17;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

/**
 * Created by xuyiwei on 2018/8/13.
 */
public class Unsupported {
    static void test(String msg,List<String> list){
        System.out.println("--- "+ msg+" ---");
        Collection<String> c = list;
        //数组拷贝不涉及长度
        Collection<String> subList = list.subList(1,8);
        Collection<String> c2 = new ArrayList<String>(subList);
        //改变数组长度
        try{  c.retainAll(c2);  }catch (Exception e){   System.out.println("retainAll(): "+e);  }
        //改变数组长度
        try{  c.removeAll(c2);  }catch (Exception e){   System.out.println("removeAll(): "+e);  }
        //改变数组长度
        try{  c.clear();  }catch (Exception e){   System.out.println("clear(): "+e);  }
        //改变数组长度
        try{  c.add("x");  }catch (Exception e){   System.out.println("add(): "+e);  }
        //改变数组长度
        try{  c.addAll(c2);  }catch (Exception e){   System.out.println("retainAll(): "+e);  }
        //改变数组长度
        try{  c.remove("C");  }catch (Exception e){   System.out.println("remove(): "+e);  }
        //不改变数组长度
        try{  list.set(0,"X");  }catch (Exception e){   System.out.println("list.set(): "+e);  }
    }

    public static void main(String[] args) {
        List<String> list = Arrays.asList("A B C D E F G H I J K L".split(" "));
        test("Modifiable Copy",list);

    }
}
